package com.knowif.pojo;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.validation.constraints.NotEmpty;

import org.springframework.validation.annotation.Validated;

import com.github.pagehelper.util.StringUtil;
import com.knowif.util.paramUtil.HtmlUtil;

@Validated
public class TutorInfo {
	private Integer id;

	/**
	 * 被收藏人数
	 */
	private Integer beCollectedNum;

	/**
	 * 咨询价格:最低价格
	 */
	@NotEmpty(message = "咨询价格不能为空")
	private Double consultPrice;

	/**
	 * 用户自述
	 */
	private String descrition;
	
	//用户自述过滤富文本的标签
	private String descrition_NotFileter;

	/**
	 * 帮助人数
	 */
	private Integer helpsNum;

	/**
	 * 优惠价格
	 */
	private Double preferentialPrice;

	/**
	 * 用户id
	 */
	@NotEmpty(message = "用户id不能为空")
	private Integer userId;

	/**
	 * 是否推荐 0默认1为推荐
	 */
	private Integer isTj;

	/**
	 * 推荐页展示排序号
	 */
	private Integer tjOrdNum;

	/**
	 * 是否展示在发现页
	 */
	private Integer isFx;

	/**
	 * 发现页展示排序
	 */
	private Integer fxOrdNum;

	private TUser tUser;

	/**
	 * 所在地
	 */
	private String location;

	/**
	 * 总评分
	 */
	private Double totalScore;

	/**
	 * 总收入
	 */
	private Double totalIncome;

	/**
	 * 是否开放约聊
	 */
	private Integer isOpenTalk;

	/**
	 * 导师亮点
	 */
	private String flashPoint;

	/**
	 * 是否开启快问
	 */
	private Integer isFastAsk;

	/**
	 * 快问价格
	 */
	private BigDecimal fastAskPrice;

	private String selfShow;


	/**
	 * 擅长话题
	 */
	List<Topic> topic;

	/**
	 * 标签
	 */
	List<Label> label;

	/**
	 * 类目
	 */
	List<UserItem> userItem;

	TutorEducationInfo tutorEducationInfo;

	/**
	 * 院校信息
	 */
	List<TutorEducationInfo> tutorEducationInfos;
	
	/**
	 * 导师的教育经历
	 */
	List<UserEducationExperience> userEducationExperiences;

	/**
	 * 高亮的字段，用于模糊查询的时候，显示高亮的属性，让用户知道这个是他要查找的
	 */
	private String highlight;
	
	
	/**
	 * 判断是否被收藏
	 */
	private int isBeCollect;

	public static List<TutorInfo> andTutorEducationInfos(List<TutorInfo> tutorInfos, List<TutorEducationInfo> tutorEducationInfos) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (tutorEducationInfos == null || tutorEducationInfos.isEmpty()) {
			return tutorInfos;
		}
		List<TutorEducationInfo> uEducations = null;
		for (TutorInfo tutorInfo : tutorInfos) {
			uEducations = new ArrayList<TutorEducationInfo>();
			for (TutorEducationInfo tutorEducationInfo : tutorEducationInfos) {
				if (tutorInfo.getId().equals(tutorEducationInfo.getTutorId())) {
					uEducations.add(tutorEducationInfo);
				}
			}
			tutorInfo.setTutorEducationInfos(uEducations);
		}
		return tutorInfos;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getBeCollectedNum() {
		return beCollectedNum;
	}

	public void setBeCollectedNum(Integer beCollectedNum) {
		this.beCollectedNum = beCollectedNum;
	}

	public Double getConsultPrice() {
		return consultPrice;
	}

	public void setConsultPrice(Double consultPrice) {
		this.consultPrice = consultPrice;
	}

	public String getDescrition() {
		if(!StringUtil.isEmpty(descrition_NotFileter)){
			descrition = HtmlUtil.getTextFromHtml(descrition_NotFileter);
		}
		return descrition;
	}

	public String getSelfShow() {
		return selfShow;
	}

	public void setSelfShow(String selfShow) {
		this.selfShow = selfShow;
	}

	public void setDescrition(String descrition) {
		this.descrition = descrition == null ? null : descrition.trim();
	}

	public Integer getHelpsNum() {
		return helpsNum;
	}

	public void setHelpsNum(Integer helpsNum) {
		this.helpsNum = helpsNum;
	}

	public Double getPreferentialPrice() {
		return preferentialPrice;
	}

	public void setPreferentialPrice(Double preferentialPrice) {
		this.preferentialPrice = preferentialPrice;
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Integer getIsTj() {
		return isTj;
	}

	public void setIsTj(Integer isTj) {
		this.isTj = isTj;
	}

	public TUser gettUser() {
		return tUser;
	}

	public void settUser(TUser tUser) {
		this.tUser = tUser;
	}

	public String getHighlight() {
		return highlight;
	}

	public void setHighlight(String highlight) {
		this.highlight = highlight;
	}

	public List<Topic> getTopic() {
		return topic;
	}

	public void setTopic(List<Topic> topic) {
		this.topic = topic;
	}

	public List<Label> getLabel() {
		return label;
	}

	public void setLabel(List<Label> label) {
		this.label = label;
	}

	public List<UserEducationExperience> getUserEducationExperiences() {
		return userEducationExperiences;
	}

	public void setUserEducationExperiences(List<UserEducationExperience> userEducationExperiences) {
		this.userEducationExperiences = userEducationExperiences;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public Double getTotalScore() {
		return totalScore;
	}

	public void setTotalScore(Double totalScore) {
		this.totalScore = totalScore;
	}

	public Double getTotalIncome() {
		return totalIncome;
	}

	public void setTotalIncome(Double totalIncome) {
		this.totalIncome = totalIncome;
	}

	public Integer getIsOpenTalk() {
		return isOpenTalk;
	}

	public void setIsOpenTalk(Integer isOpenTalk) {
		this.isOpenTalk = isOpenTalk;
	}

	public int getIsBeCollect() {
		return isBeCollect;
	}

	public void setIsBeCollect(int isBeCollect) {
		this.isBeCollect = isBeCollect;
	}

	public TutorEducationInfo getTutorEducationInfo() {
		return tutorEducationInfo;
	}

	public void setTutorEducationInfo(TutorEducationInfo tutorEducationInfo) {
		this.tutorEducationInfo = tutorEducationInfo;
	}

	public List<UserItem> getUserItem() {
		return userItem;
	}

	public void setUserItem(List<UserItem> userItem) {
		this.userItem = userItem;
	}

	public List<TutorEducationInfo> getTutorEducationInfos() {
		return tutorEducationInfos;
	}

	public void setTutorEducationInfos(List<TutorEducationInfo> tutorEducationInfos) {
		this.tutorEducationInfos = tutorEducationInfos;
	}

	public Integer getIsFastAsk() {
		return isFastAsk;
	}

	public void setIsFastAsk(Integer isFastAsk) {
		this.isFastAsk = isFastAsk;
	}

	public BigDecimal getFastAskPrice() {
		return fastAskPrice;
	}

	public void setFastAskPrice(BigDecimal fastAskPrice) {
		this.fastAskPrice = fastAskPrice;
	}

	public String getFlashPoint() {
		return flashPoint;
	}

	public void setFlashPoint(String flashPoint) {
		this.flashPoint = flashPoint;
	}
	
	public String getDescrition_NotFileter() {
		return descrition_NotFileter;
	}

	public void setDescrition_NotFileter(String descrition_NotFileter) {
		this.descrition_NotFileter = descrition_NotFileter;
	}

	public Integer getTjOrdNum() {
		return tjOrdNum;
	}

	public void setTjOrdNum(Integer tjOrdNum) {
		this.tjOrdNum = tjOrdNum;
	}

	public Integer getIsFx() {
		return isFx;
	}

	public void setIsFx(Integer isFx) {
		this.isFx = isFx;
	}

	public Integer getFxOrdNum() {
		return fxOrdNum;
	}

	public void setFxOrdNum(Integer fxOrdNum) {
		this.fxOrdNum = fxOrdNum;
	}

	// 将UserEducationExperience信息加入tusers信息
	public static List<TutorInfo> andUserEducationExperiencess(List<TutorInfo> tutorInfos,
			List<List<UserEducationExperience>> userEducationExperiencess) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (userEducationExperiencess == null || userEducationExperiencess.isEmpty()) {
			return tutorInfos;
		}
		for (TutorInfo tutorInfo : tutorInfos) {
			for (List<UserEducationExperience> userEducationExperiences : userEducationExperiencess) {
				if (tutorInfo.getId().equals(userEducationExperiences.get(0).getUserInfoId())) {
					tutorInfo.setUserEducationExperiences(userEducationExperiences);
				}
			}
		}
		return tutorInfos;
	}

	// 将labels信息加入tusers信息
	public static List<TutorInfo> andLabelss(List<TutorInfo> tutorInfos, List<List<Label>> Labelss) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (Labelss == null || Labelss.isEmpty()) {
			return tutorInfos;
		}
		for (TutorInfo tutorInfo : tutorInfos) {
			for (List<Label> labels : Labelss) {
				if (tutorInfo.getUserId().equals(labels.get(0).getUserId())) {
					tutorInfo.setLabel(labels);
				}
			}
		}
		return tutorInfos;
	}

	// 将labels信息加入tusers信息
	public static List<TutorInfo> andLabels(List<TutorInfo> tutorInfos, List<Label> labels) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (labels == null || labels.isEmpty()) {
			return tutorInfos;
		}
		List<Label> saveLabels = null;
		for (TutorInfo tutorInfo : tutorInfos) {
			saveLabels = new ArrayList<Label>();
			for (Label label : labels) {
				if (tutorInfo.getUserId().equals(label.getUserId())) {
					saveLabels.add(label);
				}
			}
			tutorInfo.setLabel(saveLabels);
		}
		return tutorInfos;
	}

	// 将topics信息加入tusers信息
	public static List<TutorInfo> andTopicss(List<TutorInfo> tutorInfos, List<List<Topic>> topicss) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (topicss == null || topicss.isEmpty()) {
			return tutorInfos;
		}
		for (TutorInfo tutorInfo : tutorInfos) {
			for (List<Topic> topics : topicss) {
				if (tutorInfo.getUserId().equals(topics.get(0).getUserId())) {
					tutorInfo.setTopic(topics);
				}
			}
		}
		return tutorInfos;
	}

	// 将topics信息加入tusers信息
	public static List<TutorInfo> andTopics(List<TutorInfo> tutorInfos, List<Topic> topics) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (topics == null || topics.isEmpty()) {
			return tutorInfos;
		}
		List<Topic> saveTopics = null;
		for (TutorInfo tutorInfo : tutorInfos) {
			saveTopics = new ArrayList<Topic>();
			for (Topic topic : topics) {
				if (tutorInfo.getUserId().equals(topic.getUserId())) {
					saveTopics.add(topic);
				}
			}
			tutorInfo.setTopic(saveTopics);
		}
		return tutorInfos;
	}

	
	
	


	// 将tutorInfos信息加入tusers信息
	public static List<TutorInfo> andTUser(List<TutorInfo> tutorInfos, List<TUser> tUsers) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (tUsers == null || tUsers.isEmpty()) {
			return tutorInfos;
		}
		for (TutorInfo tutorInfo : tutorInfos) {
			for (TUser tUser : tUsers) {
				if (tutorInfo.getUserId().equals(tUser.getId())) {
					tutorInfo.settUser(tUser);
				}
			}
		}
		return tutorInfos;
	}


	// 将UserEducationExperience信息加入tusers信息
	public static List<TutorInfo> andUserEducationExperiences(List<TutorInfo> tutorInfos,
			List<UserEducationExperience> userEducationExperiences) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<TutorInfo>();
		}
		if (userEducationExperiences == null || userEducationExperiences.isEmpty()) {
			return tutorInfos;
		}
		List<UserEducationExperience> uExperiences = null;
		for (TutorInfo tutorInfo : tutorInfos) {
			uExperiences = new ArrayList<UserEducationExperience>();
			for (UserEducationExperience userEducationExperience : userEducationExperiences) {
				if (tutorInfo.getId().equals(userEducationExperience.getUserInfoId())) {
					uExperiences.add(userEducationExperience);
				}
			}
			tutorInfo.setUserEducationExperiences(uExperiences);
		}
		return tutorInfos;
	}


	/**
	 * @author: xingyao 
	 * @Description:  得到集合中的userIds
	 * @param tutorInfos
	 * @return
	 */
	public static List<Integer> getUserIds(List<TutorInfo> tutorInfos) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<Integer>();
		}
		List<Integer> userIds = new ArrayList<Integer>();
		for (TutorInfo tutorInfo : tutorInfos) {
			userIds.add(tutorInfo.getUserId());
		}
		return userIds;
	}
	
	public static List<Integer> getTutorIds(List<TutorInfo> tutorInfos) {
		if (tutorInfos == null || tutorInfos.isEmpty()) {
			return new ArrayList<Integer>();
		}
		List<Integer> tutorIds = new ArrayList<Integer>();
		for (TutorInfo tutorInfo : tutorInfos) {
			tutorIds.add(tutorInfo.getId());
		}
		return tutorIds;
	}
	
	
	
	public static void saveUser(List<TutorInfo> tutorInfos,List<TUser> tUsers){
		if(tutorInfos == null || tutorInfos.isEmpty() || tUsers == null ||tUsers.isEmpty()){
			return;
		}
		for(TutorInfo tutorInfo : tutorInfos){
			for(TUser tUser : tUsers){
				if(tutorInfo.getUserId() != null && tutorInfo.getUserId().equals(tUser.getId())){
					tutorInfo.settUser(tUser);
				}
			}
		}
	}
	
	
	public static void saveUserItem(List<TutorInfo> tutorInfos,List<UserItem> userItems){
		if(tutorInfos == null || tutorInfos.isEmpty() || userItems == null ||userItems.isEmpty()){
			return;
		}
		List<UserItem> items = null;
		for(TutorInfo tutorInfo : tutorInfos){
			items = new ArrayList<UserItem>();
			for(UserItem userItem : userItems){
				if(tutorInfo.getUserId() != null && tutorInfo.getUserId().equals(userItem.getUserId())){
					items.add(userItem);
				}
			}
			tutorInfo.setUserItem(items);
		}
	}
	
	
	public static void saveTopics(List<TutorInfo> tutorInfos,List<Topic> topics){
		if(tutorInfos == null || tutorInfos.isEmpty() || topics == null ||topics.isEmpty()){
			return;
		}
		List<Topic> topicResult = null;
		for(TutorInfo tutorInfo : tutorInfos){
			topicResult = new ArrayList<Topic>();
			for(Topic topic : topics){
				if(tutorInfo.getUserId() != null && tutorInfo.getUserId().equals(topic.getUserId())){
					topicResult.add(topic);
				}
			}
			tutorInfo.setTopic(topicResult);
		}
	}
	
	
	public static void saveLabels(List<TutorInfo> tutorInfos,List<Label> labels){
		if(tutorInfos == null || tutorInfos.isEmpty() || labels == null ||labels.isEmpty()){
			return;
		}
		List<Label> labelResult = null;
		for(TutorInfo tutorInfo : tutorInfos){
			labelResult = new ArrayList<Label>();
			for(Label label : labels){
				if(tutorInfo.getUserId() != null && tutorInfo.getUserId().equals(label.getUserId())){
					labelResult.add(label);
				}
			}
			tutorInfo.setLabel(labelResult);
		}
	}
	
	
	public static void saveUserEducationExperiences(List<TutorInfo> tutorInfos,List<UserEducationExperience> userEducationExperiences){
		if(tutorInfos == null || tutorInfos.isEmpty() || userEducationExperiences == null ||userEducationExperiences.isEmpty()){
			return;
		} 
		List<UserEducationExperience> userEducationExpResult = null;
		for(TutorInfo tutorInfo : tutorInfos){ 
			userEducationExpResult = new ArrayList<UserEducationExperience>();
			for(UserEducationExperience userEducationExp : userEducationExperiences){
				if(tutorInfo.getId() != null && tutorInfo.getId().equals(userEducationExp.getUserInfoId())){
					userEducationExpResult.add(userEducationExp);
				}
			}
			tutorInfo.setUserEducationExperiences(userEducationExpResult);
		}
	}
}




